project(libwayqt LANGUAGES CXX C)
set(TARGET libwayqt)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(PkgConfig)
pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client)

ws_generate_local(client
    ${CMAKE_CURRENT_SOURCE_DIR}/protocols/wlr-output-management-unstable-v1.xml
    wlr-output-management-unstable-v1-client-protocol)

ws_generate_local(client
    ${CMAKE_CURRENT_SOURCE_DIR}/protocols/wlr-gamma-control-unstable-v1.xml
    wlr-gamma-control-unstable-v1-client-protocol)

ws_generate_local(client
    ${CMAKE_CURRENT_SOURCE_DIR}/protocols/treeland-output-management.xml
    treeland-output-management-client-protocol)

set(HEADERS
    Registry.hpp
    WayQtUtils.hpp
    Output.hpp
    OutputManager.hpp
    GammaControl.hpp
    TreeLandOutputManager.hpp
)

set(SOURCES
    Registry.cpp
    WayQtUtils.cpp
    Output.cpp
    OutputManager.cpp
    GammaControl.cpp
    TreeLandOutputManager.cpp
)

add_library(${TARGET}
    SHARED
    ${SOURCES}
    ${HEADERS}
)

target_sources(${TARGET}
    PRIVATE
    wlr-output-management-unstable-v1-client-protocol.c
    wlr-gamma-control-unstable-v1-client-protocol.c
    treeland-output-management-client-protocol.c
)

target_include_directories(${TARGET}
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
        $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
    PRIVATE
        ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
)

target_link_directories(${TARGET}
    INTERFACE
        $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
        $<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>
)

target_link_libraries(${TARGET}
    PUBLIC
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Gui
    PkgConfig::WaylandClient
)

# install(TARGETS wlr-display DESTINATION ${CMAKE_INSTALL_BINDIR})
